package 第六周;

/*
 * @author  YxinMiracle
 * @date  2022-05-05 11:27
 * @Gitee: https://gitee.com/yxinmiracle
 */

import java.util.Arrays;
import java.util.Comparator;

public class 完成所有任务的最少初始能量 {

    public int minimumEffort(int[][] tasks) {
        Arrays.sort(tasks, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return (o1[1]-o1[0]) - (o2[1]-o2[0]);
            }
        });
        int ans = 0;
        for (int[] task : tasks) {
            ans = Math.max(task[1],ans+task[0]);
        }
        return ans;

    }

}
